--POUR CONTROLE

define erp='erp_mli2.';
define outils='outils_mli2.';

 --CALL uvse_ExistsOrCreate('VRT_VRT');

 DELETE FROM se_VRT_VRT;

 --SELECT * FROM &erp.vrt_vrt
 --SELECT * FROM uv_pparam_masques

 /*
select * from (
SELECT &outils.stragg(source) source,vrt_cod, vrt_fam_cod, enreg_id, enreg_s, vrt_lib, vrt_lib2, obligvrt_ok, colonneaff_val, colonneordreaff_val, horsse_ok
FROM (
  SELECT 'uv' source ,g.* FROM se_VRT_VRT g
  UNION ALL
  SELECT 'se' source ,g.* FROM &erp.VRT_VRT g
  )

GROUP BY vrt_cod, vrt_fam_cod, enreg_id, enreg_s, vrt_lib, vrt_lib2, obligvrt_ok, colonneaff_val, colonneordreaff_val, horsse_ok
HAVING Count(1)!=2 ) r
ORDER BY vrt_cod  */



 INSERT INTO se_VRT_VRT
 (SELECT id vrt_cod,
         'GEN' vrt_fam_cod,
         0 enreg_id,
         'N' enreg_s,
         des vrt_lib,
         null vrt_lib2,
         Decode(typeimpl,'O','N','O') obligvrt_ok,
         1 colonneaff_val,
         1 colonneordreaff_val,
         'N' horsse_ok
     FROM  uv_pparam_masques

     );


 UPDATE se_VRT_VRT tf SET enreg_id=Nvl((select enreg_id FROM &erp.vrt_vrt f WHERE f.vrt_cod=tf.vrt_cod),0) ;
 UPDATE se_VRT_VRT tf SET enreg_id=&outils.enreg_id.NEXTVAL WHERE enreg_id IS NULL OR enreg_id =0;





 commit;





